/**
 * @package: BrickCAD
 * @className: BrickImagePanel.java
 * @package: default
 * @author: Sean O'Brien, Jack, Lester Tam, Erik Telstad
 * @date_created: November 29, 2009
 * @last_motified: November 29, 2009
 * 
 * 
 * 
 */

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.Rectangle2D;

import javax.swing.JPanel;


public class BrickImagePanel extends JPanel {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private double xc, yc, width, height;
	private Rectangle2D.Double brick;
	private Color brickColor, outlineColor;

	/**
	 * @param x
	 * @param y
	 * @param w
	 * @param h
	 */
	public BrickImagePanel(double x, double y, double w, double h) {
	   setPreferredSize(new Dimension(300, 300));
	   xc = x;
	   yc = y;
	   width = w;
	   height = h;
	   brick = new Rectangle2D.Double(xc, yc, width, height);
	   brickColor = Color.RED;
	   outlineColor = Color.BLACK;
	}
	   
	/**
	 * @return
	 */
	public double getBrickHeight() {
		return brick.height;		   
	}

	/**
	 * @return
	 */
	public double getBrickWidth() {
		return brick.width;		   
	}

	/**
	 * @param h
	 */
	public void setBrickHeight(double h) {
		brick.height = h;		   
	}

	/**
	 * @param w
	 */
	public void setBrickWidth(double w) {
	   brick.width = w;		   
	}
	   
	/**
	 * @param x
	 * @param y
	 * @param ctrX
	 * @param ctrY
	 */
	public void setLocation(double x, double y, double ctrX, double ctrY) {
	   brick.setFrameFromCenter(x, y, ctrX, ctrY);
	   repaint();
	}

	/* (non-Javadoc)
	 * @see javax.swing.JComponent#paintComponent(java.awt.Graphics)
	 */
	public void paintComponent(Graphics gc) {
		super.paintComponent(gc);
	    Graphics2D gc2d = (Graphics2D)gc;
	    draw(gc2d);
	}
	   
	/**
	 * @param gc
	 */
	public void draw(Graphics2D gc) {
	   Color oldColor = gc.getColor();
	   gc.setColor(brickColor);
	   gc.fill(brick);
	   gc.setColor(outlineColor);
	   gc.draw(brick);
	   gc.setColor(oldColor);		  
	}

}
